package com.baidumap.administrator.happystudy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.baidumap.administrator.happystudy.R;
import com.baidumap.administrator.happystudy.model.TeacherIndex;
import com.baidumap.administrator.happystudy.utils.GlideUtil;

import java.util.List;

/**
 * Created by C on 2017/3/25.
 * 更多老师
 */
public class TeacherMoreAdapter extends BaseAdapter {
    private Context mContext;
    private List<TeacherIndex.DataBean> dataBeenList;

    private LayoutInflater inflater;

    public TeacherMoreAdapter(Context context, List<TeacherIndex.DataBean> dataBeenList) {
        this.mContext = context;
        this.dataBeenList = dataBeenList;

        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return dataBeenList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {


        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.adapter_teacher_more, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.teacher_img = (ImageView) convertView.findViewById(R.id.teacher_img);
            viewHolder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            viewHolder.tv_school = (TextView) convertView.findViewById(R.id.tv_school);
            viewHolder.tv_rank = (TextView) convertView.findViewById(R.id.tv_rank);
            viewHolder.tv_questions = (TextView) convertView.findViewById(R.id.tv_questions);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.tv_name.setText(dataBeenList.get(position).getName() == null ? "新老师" : dataBeenList.get(position).getName());
        viewHolder.tv_school.setText(dataBeenList.get(position).getSchool_name() == null ? "核实中" : dataBeenList.get(position).getSchool_name());
        viewHolder.tv_rank.setText(dataBeenList.get(position).getRank());
        String qusetionnum = dataBeenList.get(position).getQuestions() == null ? "0" : dataBeenList.get(position).getQuestions();
        viewHolder.tv_questions.setText("已答题" + qusetionnum + "道");

        GlideUtil.displayTeacherImg(mContext, dataBeenList.get(position).getTeacher_pic(), viewHolder.teacher_img);
        return convertView;
    }

    class ViewHolder {
        private ImageView teacher_img;
        private TextView tv_name;
        private TextView tv_school;
        private TextView tv_rank;
        private TextView tv_questions;
    }
}
